package com.aabte.design2.behavioral.memento.v1;

/**
 * 命令对象可作为负责人。在这种情况下，命令会在修改编辑器状态之前获取一个
 * 备忘录。当需要撤销时，它会从备忘录中恢复编辑器的状态
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/4
 */
public class BackupCommand {

    private Editor editor;
    private Snapshot backup;

    public BackupCommand(Editor editor) {
        this.editor = editor;
    }

    public void makeBackup() {
        backup = editor.createSnapshot();
    }

    public void undo() {
        if (backup != null) {
            backup.restore();
        }
    }

}
